added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2008 / VBWPFDataBinding / Converters.vb
blob3d3c5ee65bccd94e025eb0d0e033cb101b1a9518
1 '****************************** Module Header ******************************'
2 ' Module Name: Converters.vb
3 ' Project: VBWPFDataBinding
4 ' Copyright (c) Microsoft Corporation.
5 '
6 ' This example demonstrates how to use DataBinding in WPF
7 '
8 ' This source is subject to the Microsoft Public License.
9 ' See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
10 ' All other rights reserved.
12 ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
13 ' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
14 ' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
15 '***************************************************************************'
17 Public Class SalaryFormmatingConverter
18 Implements IValueConverter
20 #Region "IValueConverter Members"
22 Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
23 Dim dolloars As Double = 0
24 Dim formattedSalary As String = String.Empty
26 If value Is Nothing Then
27 Throw New NullReferenceException("value can not be null")
28 Else
29 [Double].TryParse(value.ToString(), dolloars)
30 End If
31 formattedSalary = [String].Format("Total={0}$", dolloars)
32 Return formattedSalary
33 End Function
35 Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
36 Dim dolloars As Double = 0
37 If value Is Nothing Then
38 Throw New NullReferenceException("value can not be null")
39 End If
40 [Double].TryParse(value.ToString().TrimStart(New Char() {"T"c, "t"c, "o"c, "a"c, "l"c, "="c}).TrimEnd("$"c), dolloars)
41 Return dolloars
42 End Function
44 #End Region
45 End Class